﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WpfApplication1
{
    public partial class FormConfirm : Form
    {
        string id;
        RootData rootdata = new RootData();
        bool canclose = false;
        public FormConfirm(string _id)
        {
            id = _id;
            string link = String.Format("http://www.facebook.com/dialog/friends/?id={0}&app_id=268194079914408&redirect_uri=https://apps.facebook.com/AppTest/&display=popup&AccessToken={1}", id, MainWindow.AccessToken);
            InitializeComponent();
            this.Left = Screen.PrimaryScreen.Bounds.Width - this.Width - 330;
            this.Top = 450;
            if (id == "")
            {
                MessageBox.Show("Error...closing");
                this.Close();
                return;
            }
            webBrowser1.Navigate(link);
        }

        private void FormConfirm_MouseLeave(object sender, EventArgs e)
        {
            if (canclose == true)
                this.Close();
        }

        private void FormConfirm_MouseEnter(object sender, EventArgs e)
        {
            this.canclose = true;
        }

        private void FormConfirm_Enter(object sender, EventArgs e)
        {
            MessageBox.Show("Ok");
        }

        private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            if (e.Url.AbsoluteUri == "http://apps.facebook.com/AppTest/?action=1")
            {
                this.Close();
                rootdata.RemoveFriendRequest(id);
            }
            else if (e.Url.AbsoluteUri == "http://apps.facebook.com/AppTest/?action=0")
                this.Close();
        }
    }
}
